/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmCliente.java
 *
 * Created on 05-dic-2014, 10:21:44
 */
package presentacion;


import javax.swing.table.DefaultTableModel;
import Negocio.Cliente;
import Negocio.ListaCliente;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;
import javax.swing.JOptionPane;
import javax.swing.JTable;


/**
 *
 * @author sistemas
 */
public class frmCliente extends javax.swing.JFrame {

ListaCliente L=new ListaCliente();
DefaultTableModel md;
String data[][]={};
String cabeza[]={"id","Nombre","Paterno","Materno","Carnet","sexo","Fecha Nac."};
    private String dateInString;
    /** Creates new form frmCliente */
    public frmCliente() {
        initComponents();
        md=new DefaultTableModel(data,cabeza);
        tblCliente.setModel(md);
    }


           
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        opSexo = new javax.swing.ButtonGroup();
        opBusca = new javax.swing.ButtonGroup();
        btnBuscar = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblCliente = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        txtApellidoMaterno = new javax.swing.JTextField();
        OpFemenino = new javax.swing.JRadioButton();
        txtid = new javax.swing.JTextField();
        OpMasculino = new javax.swing.JRadioButton();
        txtNombreCliente = new javax.swing.JTextField();
        txtApellidoPaterno = new javax.swing.JTextField();
        txtFechaNacimiento = new javax.swing.JTextField();
        txtCarnet = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel8 = new javax.swing.JLabel();
        txtBuscar = new javax.swing.JTextField();
        btnSalir = new javax.swing.JButton();
        btnElimina = new javax.swing.JButton();
        btnEdita = new javax.swing.JButton();
        btnCancela = new javax.swing.JButton();
        btnLeerTxt = new javax.swing.JButton();
        btnEscriveTxt = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        tblCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblCliente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblClienteMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblCliente);

        jPanel1.setBackground(javax.swing.UIManager.getDefaults().getColor("InternalFrame.inactiveTitleBackground"));
        jPanel1.setForeground(java.awt.SystemColor.activeCaption);

        jLabel3.setText("Ap. Paterno");

        jLabel2.setText("Nombre");

        jLabel1.setText("Id");

        opSexo.add(OpFemenino);
        OpFemenino.setText("Femenino");

        opSexo.add(OpMasculino);
        OpMasculino.setSelected(true);
        OpMasculino.setText("Masculino");
        OpMasculino.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OpMasculinoActionPerformed(evt);
            }
        });

        jLabel5.setText("Fecha Nacimiento");

        jLabel6.setText("Sexo");

        jLabel7.setText("Carnet");

        jLabel4.setText("Ap. Materno");

        jLayeredPane1.setBackground(java.awt.SystemColor.controlHighlight);
        jLayeredPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel8.setFont(new java.awt.Font("Wide Latin", 1, 24)); // NOI18N
        jLabel8.setText("Datos Personales");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(98, 98, 98)
                .addComponent(OpMasculino)
                .addContainerGap(242, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(64, 64, 64))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                                    .addComponent(txtApellidoMaterno, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                                    .addComponent(txtFechaNacimiento, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                                    .addComponent(txtNombreCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                                    .addComponent(txtCarnet, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                                    .addComponent(txtid, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE))
                                .addGap(41, 41, 41)
                                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(73, 73, 73)
                                .addComponent(OpFemenino)))))
                .addGap(21, 21, 21))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCarnet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtNombreCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtApellidoMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtFechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(OpMasculino)
                            .addComponent(OpFemenino)))
                    .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        btnSalir.setText("Salir");

        btnElimina.setText("Eliminar");
        btnElimina.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminaActionPerformed(evt);
            }
        });

        btnEdita.setText("Editar");
        btnEdita.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditaActionPerformed(evt);
            }
        });

        btnCancela.setText("Cancelar");

        btnLeerTxt.setText("Leer TXT");
        btnLeerTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLeerTxtActionPerformed(evt);
            }
        });

        btnEscriveTxt.setText("guardar TXT");
        btnEscriveTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEscriveTxtActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnEscriveTxt)
                            .addComponent(btnLeerTxt)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 701, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(btnGuardar)
                            .addGap(18, 18, 18)
                            .addComponent(btnElimina)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(btnEdita)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btnCancela)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnSalir))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(btnBuscar))))
                .addGap(53, 53, 53))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnGuardar)
                            .addComponent(btnSalir)
                            .addComponent(btnElimina)
                            .addComponent(btnEdita)
                            .addComponent(btnCancela))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnBuscar)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnLeerTxt)
                        .addGap(14, 14, 14)
                        .addComponent(btnEscriveTxt)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
private void CargarCliente(Cliente objCliente){
    objCliente.setId(Integer.parseInt(this.txtid.getText()));
    objCliente.setNombreCliente(this.txtNombreCliente.getText());
    objCliente.setApelliodoPaterno(this.txtApellidoPaterno.getText());
    objCliente.setApellidoMaterno(this.txtApellidoMaterno.getText());
    objCliente.setFechaNaciniento(this.txtFechaNacimiento.getText());
   
   if (this.OpMasculino.isSelected()){
       objCliente.setSexo("Masculino");
   }
   else{
       objCliente.setSexo("Femenino");
   }    
    objCliente.setCarnet(Integer.parseInt(this.txtCarnet.getText()));
}
   private void d(){
       SimpleDateFormat formatter=new SimpleDateFormat("dd/MM/yyyy");
    String dateInString=this.txtFechaNacimiento.getText();
   try{ 
       Date date=formatter.parse(dateInString);
      // objCliente.setFechaNaciniento(date);             
   }
    catch (Exception e){}
   }
    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        Cliente objCliente=new Cliente();
        this.CargarCliente(objCliente);
        L.Insertar(objCliente);
        llenaT();
        //String datos[]={String.valueOf(objCliente.getId()), objCliente.getNombreCliente(),objCliente.getApelliodoPaterno(),objCliente.getApellidoMaterno(),String.valueOf(objCliente.getCarnet()),objCliente.getSexo(),String.valueOf(objCliente.getFechaNaciniento())};
       // md.addRow(datos);
        // TODO add your handling code here:
    }//GEN-LAST:event_btnGuardarActionPerformed
    public void buscar(){
     tblCliente.removeAll();
        List<Cliente> objListacli=new ArrayList<Cliente>();
       // this.txtBuscar.getText()
        
        try{ 
     objListacli=L.TaeClientePorCarnet(Integer.parseInt(this.txtBuscar.getText()));
}catch(NumberFormatException e){ 
    objListacli=L.TaeClientePorNombre(this.txtBuscar.getText()) ;
}  

             
        DefaultTableModel md1=new DefaultTableModel(data,cabeza);
        Iterator it=objListacli.listIterator();
        
        while (it.hasNext()){
            Cliente objCliente=(Cliente)it.next();
            String datos[]={String.valueOf(objCliente.getId()), objCliente.getNombreCliente(),objCliente.getApelliodoPaterno(),objCliente.getApellidoMaterno(),String.valueOf(objCliente.getCarnet()),objCliente.getSexo(),String.valueOf(objCliente.getFechaNaciniento())};
            md1.addRow(datos);
           // txtNombreCliente.setText(objCliente.getNombreCliente());      
        }
         tblCliente.setModel(md1);
    }
      public void llenaT(){
          tblCliente.removeAll();
        List<Cliente> objListacli=new ArrayList<Cliente>();
           DefaultTableModel md1=new DefaultTableModel(data,cabeza);
           objListacli=L.TaeLista();
        Iterator it=objListacli.listIterator();
        
        while (it.hasNext()){
            Cliente objCliente=(Cliente)it.next();
            String datos[]={String.valueOf(objCliente.getId()), objCliente.getNombreCliente(),objCliente.getApelliodoPaterno(),objCliente.getApellidoMaterno(),String.valueOf(objCliente.getCarnet()),objCliente.getSexo(),String.valueOf(objCliente.getFechaNaciniento())};
            md1.addRow(datos);
                 
        }
         tblCliente.setModel(md1);
          
      }

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
       // ListaCliente List=new ListaCliente();
      buscar();  
// TODO add your handling code here:
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void OpMasculinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpMasculinoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_OpMasculinoActionPerformed

    private void btnEliminaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminaActionPerformed
       int i=tblCliente.getSelectedRow() ;
       if(i ==-1){
           JOptionPane.showMessageDialog(null,"debe seleccionar " );
           }
       else{
           String ii=tblCliente.getValueAt(i, 0).toString(); 
          L.elimina(Integer.parseInt(ii));
        JOptionPane.showMessageDialog(null, ii);        
    }
       llenaT();
       guarda();
        // TODO add your handling code here:
    }//GEN-LAST:event_btnEliminaActionPerformed

     
    //******public class EscribeFichero

    public  void guarda()    {
        FileWriter fichero = null;
        PrintWriter pw = null;
        try
        {
           //fichero = new FileWriter("D:\\programacionIII\\cliente.txt");
           fichero = new FileWriter("C:\\Users\\jhow\\Desktop\\programacionIII\\cliente.txt");
           pw = new PrintWriter(fichero);

            List<Cliente> objListacli=new ArrayList<Cliente>();
         // DefaultTableModel md1=new DefaultTableModel(data,cabeza);
           objListacli=L.TaeLista();
        Iterator it=objListacli.listIterator();
         while (it.hasNext()){
            Cliente objCliente=(Cliente)it.next();
            pw.println(String.valueOf(objCliente.getId())+"," +objCliente.getNombreCliente()+","+objCliente.getApelliodoPaterno()+","+objCliente.getApellidoMaterno()+","+String.valueOf(objCliente.getCarnet())+","+objCliente.getSexo()+","+String.valueOf(objCliente.getFechaNaciniento()));
            
        }
 
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
           try {
           // Nuevamente aprovechamos el finally para 
           // asegurarnos que se cierra el fichero.
           if (null != fichero)
              fichero.close();
           } catch (Exception e2) {
              e2.printStackTrace();
           }
        }
    }

    
    
    public void  lectura(){
     
     File archivo = null;
      FileReader fr = null;
      BufferedReader br = null; 
       try {
         // Apertura del fichero y creacion de BufferedReader para poder
         // hacer una lectura comoda (disponer del metodo readLine()).
           archivo = new File ("C:\\Users\\jhow\\Desktop\\programacionIII\\cliente.txt");
         //archivo = new File ("D:\\programacionIII\\cliente.txt");
         fr = new FileReader (archivo);
         br = new BufferedReader(fr);
         // Lectura del fichero
         String linea;
         while((linea=br.readLine())!=null){
     Cliente objLeer=new Cliente(); 
             String campo[] = linea.split(",");
            
              objLeer.setId(Integer.parseInt(campo[0]));
              objLeer.setNombreCliente((campo[1]));
              objLeer.setApelliodoPaterno(campo[2]);
              objLeer.setApellidoMaterno(campo[3]);
              objLeer.setCarnet(Integer.parseInt(campo[4]));
              objLeer.setSexo(campo[5]);
              objLeer.setFechaNaciniento(campo[6]);
               
              
//           
              L.Insertar(objLeer);
              }
             
      }
      catch(Exception e){
         e.printStackTrace();
      }
       finally{
         // En el finally cerramos el fichero, para asegurarnos
         // que se cierra tanto si todo va bien como si salta 
         // una excepcion.
        
           try{                    
            if( null != fr ){   
               fr.close();     
            }                  
         }catch (Exception e2){ 
            e2.printStackTrace();
         }
      }
        
        // TODO add your handling code here:

}
    private void btnLeerTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLeerTxtActionPerformed
     //j
       lectura();  
       llenaT();
    }//GEN-LAST:event_btnLeerTxtActionPerformed

    private void btnEscriveTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEscriveTxtActionPerformed
guarda();
    }//GEN-LAST:event_btnEscriveTxtActionPerformed

    private void tblClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblClienteMouseClicked
        // TODO add your handling code here:
        int i=tblCliente.getSelectedRow();
        if(i==-1){
            JOptionPane.showMessageDialog(null, "debe selecsionar fila");
          
        }
        else{
            txtid.setText(String.valueOf(tblCliente.getValueAt(i, 0))); 
            txtNombreCliente.setText(String.valueOf(tblCliente.getValueAt(i, 1)));
            txtApellidoPaterno.setText(String.valueOf(tblCliente.getValueAt(i, 2))); 
            txtApellidoMaterno.setText(String.valueOf(tblCliente.getValueAt(i, 3))); 
            txtCarnet.setText(String.valueOf(tblCliente.getValueAt(i, 4))); 
            if(String.valueOf(tblCliente.getValueAt(i, 5))=="masculino"){
               OpMasculino.setSelected(true);
            }else{
               OpFemenino.setSelected(true); 
            }
           // OpSexo.setText(String.valueOf(tblCliente.getValueAt(i, 5)));
            txtFechaNacimiento.setText(String.valueOf(tblCliente.getValueAt(i, 6))); 
             
             
        }
        
    }//GEN-LAST:event_tblClienteMouseClicked

    private void btnEditaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditaActionPerformed
       Cliente objCliente=new Cliente();
        this.CargarCliente(objCliente);
        
         int i=tblCliente.getSelectedRow();
        String ii=tblCliente.getValueAt(i, 0).toString(); 
           String i2=tblCliente.getValueAt(i, 4).toString(); 
                 
           L.edita(Integer.parseInt(ii),objCliente);
        
        llenaT();
        guarda();
      
    }//GEN-LAST:event_btnEditaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new frmCliente().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton OpFemenino;
    private javax.swing.JRadioButton OpMasculino;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancela;
    private javax.swing.JButton btnEdita;
    private javax.swing.JButton btnElimina;
    private javax.swing.JButton btnEscriveTxt;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnLeerTxt;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.ButtonGroup opBusca;
    private javax.swing.ButtonGroup opSexo;
    private javax.swing.JTable tblCliente;
    private javax.swing.JTextField txtApellidoMaterno;
    private javax.swing.JTextField txtApellidoPaterno;
    private javax.swing.JTextField txtBuscar;
    private javax.swing.JTextField txtCarnet;
    private javax.swing.JTextField txtFechaNacimiento;
    private javax.swing.JTextField txtNombreCliente;
    private javax.swing.JTextField txtid;
    // End of variables declaration//GEN-END:variables

    private void buscar(JTable tblCliente, String text) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    

   
    

   
}
     
